//
//  YQLNavigationController.swift
//  YQL_WeiBo
//
//  Created by apple on 2016/11/12.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class YQLNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
    }
    //重写这个方法自定义navigationController下面所有的控制器的返回按钮,并设置除rootViewController以外的所有控制器都隐藏tabBar
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        let count = childViewControllers.count
        
        if count > 0 {
            //设置返回按钮为自定义按钮//通过调用自定义的UIBarButtonItem的分类中的便利构造方法添加navigationItem的右侧按钮
            let leftBackButton = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(clickBacButton))
            
            viewController.navigationItem.leftBarButtonItem = leftBackButton
            
            //设置隐藏tabBar
            viewController.hidesBottomBarWhenPushed = true
        }
        
        //需要super
        super.pushViewController(viewController, animated: animated)
    }
    
    //返回按钮的点击事件
    @objc private func clickBacButton() {
        
        self.popViewController(animated: true)
        
    }



}
